<?php
class NewsController extends DRX_Controller 
{
    function prepareNewsLayout()
    {
        $smarty 	= DRX::load("smarty");
        
        $layout     = new Layout();
		$args['topmenu_id'] = NEWS_ID;
		$layout->prepareLayout($args);
		
		$news = new News();
		$news_list = $news->getAllShowNews();
		$smarty->assign("news_list",$news_list);
		
		$smarty->assign("title",NEWS_TITLE);
    }
    
    function prepareShowNews($news_id)
    {
        $smarty 	= DRX::load("smarty");
        
        $news = new News();
		$newsInfo = $news->getShownedNewsInfoByID($news_id);
		if ($newsInfo->fetch())
		{
		    $news_content = $newsInfo->news_content;
		    $news_time    = $newsInfo->news_time;
		    $news_modified= $newsInfo->news_modified;
		    $news_title   = $newsInfo->news_title;
		    $smarty->assign("news_title",$news_title);
		    $smarty->assign("news_content",$news_content);
		    $smarty->assign("news_time",$news_time);
		    $smarty->assign("news_modified",$news_modified);
		    return true;
		}
		else
		{		    
		    return false;
		}
    }
    
    function pageAction()
    {
        global $arrArgs;
        $news_id = $arrArgs[0];
        $smarty 	= DRX::load("smarty");
		
		$this->prepareNewsLayout();
		
	    if (!($this->prepareShowNews($news_id)))
	    {
	        redirect(APPLICATION_URL . NEWS_URL);;
	    }
	    $content	= $smarty->fetch("news/news.tpl");
	    $smarty->assign("content",$content);
		$smarty->display("solvay.tpl");
    }
    
	function indexAction()
	{
		$smarty 	= DRX::load("smarty");
		
		$this->prepareNewsLayout();
		
		$news = new News();
		$latestNewsID = $news->getHighestOrderNewsID();
		
		if (!($this->prepareShowNews($latestNewsID)))
		{
		    $smarty->assign("content","No news");
		}
		$content	= $smarty->fetch("news/news.tpl");
	    $smarty->assign("content",$content);
		$smarty->display("solvay.tpl");
	}
}
?>
